<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\cms\admin\model;

use think\Model;
use app\admin\model\Catalog;

class Banner extends Model
{
    protected $name = 'cms_banner';

    // 设置json类型字段
    protected $json = ['url'];

    // 设置JSON数据返回数组
    protected $jsonAssoc = true;

    // 搜索器
    public function searchCatalogAttr($query, $value, $array)
    {
        if (! empty($value)) {
            $query->where("catalog_id", "find in set", $value);
        }
    }

    public function searchKeywordAttr($query, $value, $array)
    {
        if (! empty($value)) {
            $query->where("title|c_title|description",'like', '%' . $value . '%');
        }
    }

    public function searchStatusAttr($query, $value, $array)
    {
        if ($value !== '') { 
            $query->where('status', $value);
        }
    }
    
    public function setCatalogIdAttr($value, $array)
    {
        return implode(',', $value);
    }

    // 获取器
    public function getCatalogIdAttr($value, $array)
    {
        return $value ? array_map('intval', explode(',', $value)) : [];
    }
}